package com.timothy.fund.adapter;

import java.util.ArrayList;
import java.util.List;

import com.timothy.fund.bean.FundCatagory;
import com.timothy.fund.ui.R;
import com.timothy.fund.ui.StockAListActivity;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

public class FundCatagoryAdaptor extends BaseAdapter {

	List<FundCatagory> fcList = new ArrayList<FundCatagory>();
	private LayoutInflater mInflater;
	private Context mContext;
	
	public FundCatagoryAdaptor(List<FundCatagory> fcList,Context mContext){
		this.fcList = fcList;
		mInflater = LayoutInflater.from(mContext);  
		this.mContext = mContext; 
	}

	@Override
	public int getCount() {
		return fcList.size();
	}

	@Override
	public Object getItem(int position) {
		return fcList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
    	
		ViewHolder holder;  
        if (convertView == null){  
            holder = new ViewHolder();  
            convertView = mInflater.inflate(R.layout.main_item, null);  
            holder.fCatagory = (Button) convertView.findViewById(R.id.fundCategory);  
            convertView.setTag(holder);  
        }else {  
            holder = (ViewHolder) convertView.getTag();  
        }  
        
        FundCatagory fc = fcList.get(position);
        
        holder.fCatagory.setText(fc.getName());  
        holder.fCatagory.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				
//				Intent intent = new Intent();
//				intent.setClass( mContext, StockAListActivity.class);
//				startActivity(intent);
			}
		});
        return convertView; 
	}
	

	static class ViewHolder{
		Button fCatagory;
	}

}
